package com.team2.outpatient_sys.service.impl;

import com.github.pagehelper.PageHelper;
import com.team2.outpatient_sys.dao.DepartmentDao;
import com.team2.outpatient_sys.pojo.Department;
import com.team2.outpatient_sys.service.AdminDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminDepartmentServiceImpl implements AdminDepartmentService {
    @Autowired
    private DepartmentDao departmentDao;

    /**
     * 添加新科室的服务的实现
     * @param department 添加的科室实例对象
     * @return 添加新科室服务是否成功
     */
    @Override
    public boolean addNew(Department department) {
        int affectedRows = departmentDao.insertNew(department);
        return affectedRows == 1;
    }

    /**
     * 逐一修改科室信息所有字段的服务的实现
     * @param department 修改的科室实例对象
     * @return 修改科室信息的服务是否成功
     */
    @Override
    public boolean updateWhole(Department department) {
        int affectedRows = departmentDao.updateByWhole(department);
        return affectedRows == 1;
    }

    /**
     * 根据id删除某一科室信息的服务的实现
     * @param departmentId 科室信息的id
     * @return 删除科室信息是否成功
     */
    @Override
    public boolean deleteById(Integer departmentId) {
        int affectedRows = departmentDao.deleteById(departmentId);
        return affectedRows == 1;
    }

    /**
     * 获取所有科室信息的服务的实现
     * @return 获取到的所有科室数据的List集合
     */
    @Override
    public List<Department> getAll() {
        return departmentDao.queryAll();
    }

    /**
     * 根据id获取对应科室信息的服务的实现
     * @param deptId 需要获取科室信息的科室id
     * @return 获取到的科室信息的封装对象
     */
    @Override
    public Department getById(Integer deptId) {
        return departmentDao.queryById(deptId);
    }

    /**
     * 使用分页插件查询某一分页的科室信息的实现
     * @param pageNum 查询的分页页码
     * @param pageSize 每一分页的数据个数
     * @return 查询的所有科室信息，返回以提供给PageHelper处理得到PageInfo
     */
    public List<Department> getByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return departmentDao.queryAll();
    }
}
